package com.hsg.common.otherlogin

import android.content.Intent
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.util.Log
import android.widget.Button
import android.widget.Toast
import com.google.firebase.auth.ktx.auth
import com.google.firebase.ktx.Firebase
import com.hsg.common.thirdloginutil.bean.ThirdLoginRespond
import com.hsg.common.thirdloginutil.login.fb.FacebookLogin
import com.hsg.common.thirdloginutil.login.google.GoogleLogin
import com.hsg.common.thirdloginutil.login.line.LineLogin
import com.hsg.common.thirdloginutil.login.twitter.TwitterLogin

class MainActivity : AppCompatActivity() {
    private val TAG = "otherlogin"
    private var facebookLogin : FacebookLogin? = null
    private var twitterLogin : TwitterLogin? = null
    private var lineLogin : LineLogin? = null
    private var googleLogin : GoogleLogin? = null
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)

        val sha1 = SignatureUtil.getSignatureSHA1WithColon(this, packageName)
        val hash = SignatureUtil.getHashKey(this, packageName)

//        googleLogin = GoogleLogin(this,
//            googleServerClientId = "259287201199-s854ief4lsb0kkjl3kgnnck22pisbe3n.apps.googleusercontent.com",
//            filterByAuthorizedAccounts = false) { respond: ThirdLoginRespond? ->
//            Log.i(TAG, "google respond: $respond")
//            Toast.makeText(this, respond.toString(), Toast.LENGTH_SHORT).show()
//        }
//        lineLogin = LineLogin(this, "1657543992") { respond: ThirdLoginRespond? ->
//            Log.i(TAG, "line respond: $respond")
//            Toast.makeText(this, respond.toString(), Toast.LENGTH_SHORT).show()
//        }

        findViewById<Button>(R.id.fb).setOnClickListener {
//            facebookLogin = FacebookLogin(this) { respond: ThirdLoginRespond? ->
//                Log.i(TAG, "facebook respond: $respond")
//                Toast.makeText(this, respond.toString(), Toast.LENGTH_SHORT).show()
//            }
            facebookLogin?.startLogin()
        }

        findViewById<Button>(R.id.twitter).setOnClickListener {
            twitterLogin = TwitterLogin(this) { respond: ThirdLoginRespond? ->
                Log.i(TAG, "twitter respond: $respond")
                Toast.makeText(this, respond.toString(), Toast.LENGTH_SHORT).show()
            }
            twitterLogin?.startLogin()
        }

        findViewById<Button>(R.id.line).setOnClickListener {
            lineLogin?.startLogin()
        }

        findViewById<Button>(R.id.google).setOnClickListener {
            googleLogin?.startLogin()
        }

        findViewById<Button>(R.id.signature).setOnClickListener {
            Log.i(TAG, "sha1 : $sha1 \n hash : $hash")
        }

        findViewById<Button>(R.id.signOut).setOnClickListener {
            facebookLogin?.signOut()
            googleLogin?.signOut()
            twitterLogin?.signOut()
        }
    }

    override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
        super.onActivityResult(requestCode, resultCode, data)
        facebookLogin?.handleLoginResult(requestCode, resultCode, data)
        lineLogin?.handleLoginResult(requestCode, resultCode, data)
        googleLogin?.handleLoginResult(requestCode, resultCode, data)
    }
}